package com.login.filters;

import java.io.IOException;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.carorderdetail.model.CarOrderDetailVO;
import com.member.model.*;

public class ExchangeCashFilter implements Filter {

	@Override
	public void destroy() {
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain arg2) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest)request;
		HttpServletResponse res = (HttpServletResponse)response;
		HttpSession session = req.getSession();
		String account = (String) session.getAttribute("account");
		MemberService memSvc = new MemberService();
		String member_id = memSvc.getMemId(account);
		
		int cash = 0;
		List<CarOrderDetailVO> list = memSvc.getAllOrderDetail(member_id, "0");
		for (CarOrderDetailVO codVO : list) {
			cash = cash + codVO.getFee();
		}
		
		if (memSvc.getAllExchByMemId(member_id, 0).size() != 0) {
			res.sendRedirect(req.getContextPath() + "/exchangecash/waitfor.jsp");
			return;
		}
		
		if ((memSvc.getOneMem(member_id).getBalance() - cash) > 0) {
			
		}
		
		
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		
	}

}
